package com.wlc.base.lambda;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 测试lambda表达式
 * @date 2021-07-14 08:40
 */
public class TestLambda3 {

    public static List getList(Supplier<List> supplier) {
        return supplier.get();
    }

    public void method01() {
        // 调用公getList 方法
        // 1、匿名类
        Supplier<List> listSupplier = new Supplier<List>() {
            @Override
            public List get() {
                return new ArrayList();
            }
        };
        List list = getList(listSupplier);
        list.add(new Hero("hello", 2, 3));
        list.forEach(System.out::print);
        // 2、使用lambda表达式调用
        List list1 = getList(() -> new ArrayList());
        list1.add(new Hero("hello 2", 20, 4));
        list1.forEach(System.out::print);
        // 3、引用构造器
        List list2 = getList(ArrayList::new);
        list2.add(new Hero("hello 3", 13, 4));
        list2.forEach(System.out::print);
    }

    public static void main(String[] args) {
        TestLambda3 testLambda3 = new TestLambda3();
        testLambda3.method01();
    }
}
